/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#ifndef __ENTITY_COMPONENT_H__
#define __ENTITY_COMPONENT_H__

#include "Component.h"

namespace PQEngine
{
	enum EntityMaterialState
	{
		ENTITY_MATERIAL_NORMAL,
		ENTITY_MATERIAL_HIGHLIGHT,

		//Add new mesh material state just above this line
		ENTITY_MATERIAL_COUNT
	};

	/*This class is component used to control ogre movable mesh entities.
	*/
	class EntityComponent
		: public Component
	{
	public:
		typedef std::vector<Ogre::AnimationState*> AnimationStateList;
	public:
		static EntityComponent* get(int id);
		EntityComponent(Ogre::Entity* entity);
		~EntityComponent();

		int getNumSubMesh();
		std::string getSubMeshMaterialName(unsigned short index);
		void setMaterialName(std::string materialName);
		void setNormalMaterial();

		float getRadius();
		Ogre::Vector3 getBoundingBoxSize(void) const;
		Ogre::AxisAlignedBox getBoundingBox(void) const;
		Ogre::AxisAlignedBox getWorldBoundingBox(void) const;

		void setAnimState(bool state);

		inline Ogre::Entity* getEntity(){return _entity;}
		inline Ogre::String getEntityName()
		{
			if(_entity){
				return _entity->getName();
			}
		}

		inline Ogre::String getMeshName()
		{
			if(_entity){
				return _entity->getMesh()->getName();
			}
			return "";
		}

		inline StringVector getAnimationNames(){return _animationNames;}
		inline void selectAnimation(int index){_animIndex=index;}
		inline void setDisplaySkeleton(bool display){_entity->setDisplaySkeleton(display);}
		inline void hide(){_entity->setVisible(false);}
		inline void show(){_entity->setVisible(true);}

		void update(float deltaT);

		/*High light the mesh.
		@param lighted Whether the mesh should be highlighted.
		*/
		void highLight(bool lighted);
		
	private:
		void initSubEntities();
		void initAnimations();
	private:
		Ogre::Entity* _entity;

		StringVector _animationNames;
		AnimationStateList _animationStates;
		int _animIndex;//current selected animation index
		bool _animEnabled;//current anim enabled
		
		//each slot is an array of sub entity material
		std::vector<Ogre::MaterialPtr> _materials[ENTITY_MATERIAL_COUNT];//

		bool _highLighted;//
	};
}

#endif
